package com.example.scaffolding.db.dao

import androidx.lifecycle.LiveData
import androidx.paging.DataSource
import androidx.room.*
import com.example.scaffolding.db.bean.User

@Dao
interface UserDao {
    /**
     * return a DataSource.Factory for LivePagedList
     *
     * @return
     */
    @Query("SELECT * FROM user ORDER BY id DESC")
    fun userById(): DataSource.Factory<Int?, User?>?

    /**
     * return the List type
     *
     * @return
     */
    @get:Query("SELECT * FROM user")
    val users: List<User?>?

    /**
     * return the LiveData type
     *
     * @return
     */
    @get:Query("SELECT * FROM user")
    val liveDataUsers: LiveData<List<User?>?>?

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    fun insert(vararg users: User?)

    @Delete
    fun delete(user: User?)

    @Update
    fun update(user: User?)
}